package com.xmh.datasource.demo.config;

import com.xmh.datasource.demo.content.SqlDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

@Slf4j
public class SqlDataSourceRouter extends AbstractRoutingDataSource {

    @Override
    protected Object determineCurrentLookupKey() {
        String dataSource = SqlDataSourceContextHolder.get();

        log.info("current data source : {}", dataSource);

        return dataSource;
    }
}
